﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ECCSystem
{
    public partial class frmJapans : Form
    {
        private BizRule.ClsJapans objJapans;
        private BizRule.ClsCommon objCommon;
        private int intUpdateFlag;

        public frmJapans()
        {
            InitializeComponent();
        }

        private void frmJapans_Load(object sender, EventArgs e)
        {
            try
            {
                intUpdateFlag = 0;
                string strECCDate;
                DataSet objDS = new DataSet();
                //get ECCDate for get today's data
                objCommon = new ECCSystem.BizRule.ClsCommon();
                strECCDate = objCommon.GetECCDate(DateTime.Now).Substring(0, 10);
                objJapans = new ECCSystem.BizRule.ClsJapans();
                objDS = (DataSet)objJapans.GetTodaysData(strECCDate);
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    this.InitTodaysData(objDS);
                    //intUpdateFlag = 1 is edit status
                    intUpdateFlag = 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ECC Catch Error");
            }
        }

        private void frmJapans_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form frmMain = new frmMain();
            frmMain.Show();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (intUpdateFlag == 0)
                {
                    int intRowsAffected = 0;
                    objJapans = new ECCSystem.BizRule.ClsJapans();
                    intRowsAffected = objJapans.AddJapans(Convert.ToInt32(txtTimeSpan1.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan2.Text.ToString()), Convert.ToInt32(txtTimeSpan3.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan4.Text.ToString()), Convert.ToInt32(txtTimeSpan5.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan6.Text.ToString()), Convert.ToInt32(txtTimeSpan7.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan8.Text.ToString()), Convert.ToInt32(txtTimeSpan9.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan10.Text.ToString()), Convert.ToInt32(txtTimeSpan11.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan12.Text.ToString()), Convert.ToInt32(txtTimeSpan13.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan14.Text.ToString()), Convert.ToInt32(txtTimeSpan15.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan16.Text.ToString()), Convert.ToInt32(txtTimeSpan17.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan18.Text.ToString()), Convert.ToInt32(txtTimeSpan19.Text.ToString()));
                    if (intRowsAffected <= 0)
                    {
                        MessageBox.Show("保存していません！", "ECC Information");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("操作成功しました。", "ECC Information");
                        this.Close();
                    }
                }
                if (intUpdateFlag == 1)
                {
                    int intRowsAffected = 0;
                    intRowsAffected = objJapans.EditJapans(Convert.ToInt32(txtTimeSpan1.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan2.Text.ToString()), Convert.ToInt32(txtTimeSpan3.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan4.Text.ToString()), Convert.ToInt32(txtTimeSpan5.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan6.Text.ToString()), Convert.ToInt32(txtTimeSpan7.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan8.Text.ToString()), Convert.ToInt32(txtTimeSpan9.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan10.Text.ToString()), Convert.ToInt32(txtTimeSpan11.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan12.Text.ToString()), Convert.ToInt32(txtTimeSpan13.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan14.Text.ToString()), Convert.ToInt32(txtTimeSpan15.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan16.Text.ToString()), Convert.ToInt32(txtTimeSpan17.Text.ToString())
                        , Convert.ToInt32(txtTimeSpan18.Text.ToString()), Convert.ToInt32(txtTimeSpan19.Text.ToString()));
                    if (intRowsAffected <= 0)
                    {
                        MessageBox.Show("保存していません！", "ECC Information");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("操作成功しました。", "ECC Information");
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ECC Catch Error");
            }
        }

        //initialize saved today's data into textbox
        private void InitTodaysData(DataSet objDS)
        {
            txtTimeSpan1.Text = objDS.Tables[0].Rows[0][1].ToString();
            txtTimeSpan2.Text = objDS.Tables[0].Rows[0][2].ToString();
            txtTimeSpan3.Text = objDS.Tables[0].Rows[0][3].ToString();
            txtTimeSpan4.Text = objDS.Tables[0].Rows[0][4].ToString();
            txtTimeSpan5.Text = objDS.Tables[0].Rows[0][5].ToString();
            txtTimeSpan6.Text = objDS.Tables[0].Rows[0][6].ToString();
            txtTimeSpan7.Text = objDS.Tables[0].Rows[0][7].ToString();
            txtTimeSpan8.Text = objDS.Tables[0].Rows[0][8].ToString();
            txtTimeSpan9.Text = objDS.Tables[0].Rows[0][9].ToString();
            txtTimeSpan10.Text = objDS.Tables[0].Rows[0][10].ToString();
            txtTimeSpan11.Text = objDS.Tables[0].Rows[0][11].ToString();
            txtTimeSpan12.Text = objDS.Tables[0].Rows[0][12].ToString();
            txtTimeSpan13.Text = objDS.Tables[0].Rows[0][13].ToString();
            txtTimeSpan14.Text = objDS.Tables[0].Rows[0][14].ToString();
            txtTimeSpan15.Text = objDS.Tables[0].Rows[0][15].ToString();
            txtTimeSpan16.Text = objDS.Tables[0].Rows[0][16].ToString();
            txtTimeSpan17.Text = objDS.Tables[0].Rows[0][17].ToString();
            txtTimeSpan18.Text = objDS.Tables[0].Rows[0][18].ToString();
            txtTimeSpan19.Text = objDS.Tables[0].Rows[0][19].ToString();
        }

        //Check entry data must be number
        private void txtTimeSpan1_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan2_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan3_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan4_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan5_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan6_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan7_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan8_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan9_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan10_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan11_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan12_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan13_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan14_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan15_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan16_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan17_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan18_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

        private void txtTimeSpan19_KeyPress(object sender, KeyPressEventArgs e)
        {
            objCommon = new ECCSystem.BizRule.ClsCommon();
            objCommon.TextKeyPress(e);
        }

    }
}